home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / stub_lib / bitmap.c next >
Encoding:
C/C++ Source or Header  |  1989-04-03  |  2.7 KB  |  118 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: bitmap.c,v 4.2 88/07/07 09:08:51 sau Exp $
  9.     $Source: /tmp/mgrsrc/src/oblit/RCS/bitmap.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/src/oblit/RCS/bitmap.c,v $$Revision: 4.2 $";
  12.  
  13. /*  generic bitblit code routines*/
  14.  
  15. #include "bitmap.h"
  16.  
  17. /* open the display */
  18.  
  19. BITMAP *
  20. bit_open(name)
  21. char *name;            /* name of frame buffer */
  22. {
  23.    BITMAP *result;
  24.    char *malloc();
  25.  
  26.    if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  27.       return (BIT_NULL);
  28.  
  29.     /* do what you need to do here yo initialize the display */
  30.  
  31.    result->primary = result;
  32.    result->data = 0;
  33.    result->x0 = 0,
  34.    result->y0 = 0,
  35.    result->wide = 1000;
  36.    result->high = 900;
  37.    result->type = _SCREEN;
  38.    return (result);
  39. }
  40.  
  41. /* destroy a bitmap, free up space (might nedd special code for the display) */
  42.  
  43. int
  44. bit_destroy(bitmap)
  45. BITMAP *bitmap;
  46. {
  47.    if (bitmap == (BITMAP *) 0)
  48.       return (-1);
  49.    if (IS_MEMORY(bitmap) && IS_PRIMARY(bitmap))
  50.       free(bitmap->data);
  51.    free(bitmap);
  52.    return (0);
  53. }
  54.  
  55. /* create a bitmap as a sub-rectangle of another bitmap */
  56.  
  57. BITMAP *
  58. bit_create(map, x, y, wide, high)
  59. BITMAP *map;
  60. int x, y, wide, high;
  61. {
  62.    char *malloc();
  63.    register BITMAP *result;
  64.  
  65.    if (x + wide > map->wide)
  66.       wide = map->wide - x;
  67.    if (y + high > map->high)
  68.       high = map->high - y;
  69.    if (wide < 1 || high < 1)
  70.       return (BIT_NULL);
  71.  
  72.    if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  73.       return (BIT_NULL);
  74.  
  75.    result->data = map->data;
  76.    result->x0 = map->x0 + x;
  77.    result->y0 = map->y0 + y;
  78.    result->wide = wide;
  79.    result->high = high;
  80.    result->primary = map->primary;
  81.    result->type = map->type;
  82.    return (result);
  83. }
  84.  
  85. /* allocate space for, and create a memory bitmap */
  86.  
  87. BITMAP *
  88. bit_alloc(wide, high, data, bits)
  89. unsigned short wide, high;
  90. DATA data;
  91. int bits;    /* in preparation for color */
  92. {
  93.    char *malloc();
  94.    register BITMAP *result;
  95.    register int size;
  96.  
  97.    if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  98.       return (result);
  99.  
  100.    result->x0 = 0;
  101.    result->y0 = 0;
  102.    result->high = high;
  103.    result->wide = wide;
  104.  
  105.    size = BIT_SIZE(result);
  106.  
  107.    if (data != (DATA ) 0)
  108.       result->data = data;
  109.    else if ((result->data = (DATA ) malloc(size)) == (DATA ) 0) {
  110.       free(result);
  111.       return ((BITMAP *) 0);
  112.    }
  113.  
  114.    result->primary = result;
  115.    result->type = _MEMORY;
  116.    return (result);
  117. }
  118.